<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>

</head>
<script type="text/javascript">
	$(function(){
		 $('#addline').dialog('close');
		 $('#updateline').dialog('close');
		
		 
		$('#lines').datagrid({    
		    url:'${pageContext.request.contextPath}/selectlines',    
		    columns:[[
                {field:'checked',checkbox:true,width:100},
                {field:'lineId',title:'路线编号',width:100,hidden:true},  
		        {field:'lineName',title:'路线名字',width:100},  
		        {field:'beginPoint',title:'起始路线',width:100}, 
		        {field:'endPoint',title:'目标地点',width:100}, 
		    ]],
		    pagination:true,
		    striped:true,
		    
		toolbar : [ {
			iconCls : 'icon-add',
			text : '新增',
			handler : function() {
				  $('#addline').dialog('open')
				  
				  $("#addline").dialog({
					  onClose:function(){
						  $("#addl").form('clear');
						  $("#linen").hide();
					      $("#lineb").hide();
					      $("#linee").hide();
					     
					  }
				  })
			    	
			}	
		}, '-', {
			iconCls : 'icon-remove',
			text : '删除',
			handler : function() {
				
				var lines='';
				var ls = $("#lines").datagrid('getSelections');
				$.messager.confirm('提示', '确认删除？', function(r) {
				$.each(ls,function(n,v){
					lines=lines+v.lineId+','
					
				});
				$.ajax({
					type:'post',
					url:'${pageContext.request.contextPath}/deleteline',
					data:{'lines':lines},
					dataType:"text",
					
					success:function(data){
						
					   if(data=="true"){
						   $("#lines").datagrid('reload'); 
					   }
					
					}
				})
				})
			}
		}, '-', {
			iconCls : 'icon-edit',
			text : '修改',
			handler : function() {
				var ls = $("#lines").datagrid('getSelections');
				if (ls.length != 1) {
					$.messager.confirm('提示', '请选择一条数据', function(r) {
						if (r) {
							$("#lines").datagrid('unselectAll');
						}
					})
				} else {
					$('#updateline').dialog('open');
					var line = ls[0];
					 $('#updatel').form('load',line);

				}
			}
		} ],
		striped : true,
		rownumbers : true,
		});  

		//配置修改表单
		$("#updatel").form({
			
			url:'${pageContext.request.contextPath}/updateline',
			success:function(data){
				
				if(data=="true"){
					$('#updateline').dialog('close');
					$("#updatel").form('clear');
					$.messager.alert('我的消息','更新成功','info',function(){
						$('#lines').datagrid('reload');
					});
				 }else{
					 
				 }
			}
		});
		
		
		//配置增加表单
		$("#addl").form({
			url:'${pageContext.request.contextPath}/addline',
			success:function(data){
				 if(data=="true"){
					 $('#addline').dialog('close'); 
					 $('#lines').datagrid('reload');
					 $.messager.alert('我的消息','添加信息成功','info',function(){
							$('#goods').datagrid('reload');
						});
				 }else{
					 $.messager.alert('我的消息','添加信息失败，重新添加','info',function(){
							$("#addl").form('clear');
						});
				 }
			}	 
		});
		$("#beginPoint").blur(function(){
				var str = $("#beginPoint").val();
				if(!(/[\u4e00-\u9fa5]/.test(str))||str.length==0){
					$("#lineb").show();
					$("#zj").linkbutton({disabled:true});
				}else{
					$("#lineb").hide();
					$("#zj").linkbutton({disabled:false});
				}
			});

	
	$("#endPoint").blur(function() {
			var str = $("#endPoint").val();
			if (!(/[\u4e00-\u9fa5]/.test(str)) || str.length == 0) {
				$("#linee").show();
				$("#zj").linkbutton({
					disabled : true
				});
			} else {
				$("#linee").hide();
				$("#zj").linkbutton({
					disabled : false
				});
			};
	});
	});
	
	
		

	

	function addForm() {
		$("#addl").form('submit');
	}
	function updateForm() {

		$("#updatel").form('submit');
	}
</script>
<body>
     
    <table id="lines"></table> 
    
    <!-- 增加框 -->
    <div id="addline" class="easyui-dialog" title="增加路线信息" 
		style="width: 300px; height: 350px;" data-options="modal:true" >
		<form id="addl" method="post">
			
			<div style="margin-bottom: 20px">
				<span>路线名称</span>
				<input class="easyui-textbox" name="line.lineName" style="width: 100%"
					data-options="required:true">
			</div>
			
			<div style="margin-bottom: 20px">
				<span>路线起始位置</span>
				<input class="easyui-validatebox" name="line.beginPoint" style="width: 100%"
					data-options="required:true"  id="beginPoint"><span style="display:none;color: red" id="lineb">对不起，请输入中文!</span>
			</div>
			
			
			<div style="margin-bottom: 20px">
				<span>路线终止位置</span>
				<input class="easyui-validatebox" name="line.endPoint" style="width: 100%"
					data-options="required:true" id="endPoint"><span style="display:none;color: red" id="linee">对不起，请输入中文!</span>
			</div>
		
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="addForm()" style="width: 80px" id="zj">提交</a> 
		</div>
	</div>
	
	<!-- 修改框 -->
	<div id="updateline" class="easyui-dialog" title="修改路线信息" 
		style="width: 300px; height: 350px;" data-options="modal:true" >
		<form id="updatel" method="post">
			<div style="margin-bottom: 20px;display:none"  >
				<span>路线id</span>
				<input class="easyui-textbox" name="lineId" style="width: 100%"
					data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>路线名字</span>
				<input class="easyui-textbox" name="lineName" style="width: 100%"
					data-options="required:true">
			</div>
		     <div style="margin-bottom: 20px">
				<span>路线起始位置</span>
				<input class="easyui-textbox" name="beginPoint" style="width: 100%"
					data-options=""   readonly="readonly"><span style="display:none;color: red" id="linen">对不起，请输入中文!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>路线终止位置</span>
				<input class="easyui-textbox" name="endPoint" style="width: 100%"
					data-options=""    readonly="readonly"><span style="display:none;color: red" id="linen">对不起，请输入中文!</span>
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="updateForm()" style="width: 80px"   id="xg">提交</a> 
		</div>
	</div>	
</body>
 
</body>
</html>